import java.util.Scanner;

public class Test22 {

    static class ListNode {
        int val;
        ListNode next;

        ListNode(int val) {
            this.val = val;
            next = null;
        }
    }

    public static ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if (headA == null || headB == null) {
            return null;
        }

        ListNode curA = headA;
        ListNode curB = headB;
        int lenA = 0, lenB = 0;

        // 计算链表长度
        while (curA != null) {
            lenA++;
            curA = curA.next;
        }
        while (curB != null) {
            lenB++;
            curB = curB.next;
        }

        curA = headA;
        curB = headB;

        // 让较长的链表先走长度差
        if (lenA > lenB) {
            for (int i = 0; i < lenA - lenB; i++) {
                curA = curA.next;
            }
        } else {
            for (int i = 0; i < lenB - lenA; i++) {
                curB = curB.next;
            }
        }

        // 同时遍历找交点
        while (curA != null && curB != null) {
            if (curA == curB) {
                return curA;
            }
            curA = curA.next;
            curB = curB.next;
        }

        return null;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        // 读取第一个链表
        int n1 = sc.nextInt();
        ListNode head1 = null, tail1 = null;
        for (int i = 0; i < n1; i++) {
            int val = sc.nextInt();
            ListNode node = new ListNode(val);
            if (head1 == null) {
                head1 = node;
                tail1 = node;
            } else {
                tail1.next = node;
                tail1 = node;
            }
        }

        // 读取第二个链表
        int n2 = sc.nextInt();
        ListNode head2 = null, tail2 = null;
        for (int i = 0; i < n2; i++) {
            int val = sc.nextInt();
            ListNode node = new ListNode(val);
            if (head2 == null) {
                head2 = node;
            } else {
                tail2.next = node;
            }
            tail2 = node;
        }

        //读取相加位置
        int meetIndex = sc.nextInt();
        if(meetIndex >= 0 && meetIndex < n1) {
            ListNode meetNode = head1;
            for(int i = 0; i < meetIndex; i++) {
                meetNode = meetNode.next;
            }
            //连接
            tail2.next = meetNode;
        }

        ListNode result = getIntersectionNode(head1, head2);
        if (result != null) {
            System.out.println("相交节点：" + result.val);
        } else {
            System.out.println("两个链表没有相交节点");
        }
    }
}